package com.lonely.fx;

import javafx.application.Application;
import javafx.application.HostServices;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Hyperlink;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

/**
 * @date: 2022-07-06 21:24
 * @author: ztkj-hzb
 * @description: 超链接
 **/
public class HyperlinkSettingMain extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    /**
     * 超链接
     */
    @Override
    public void start(Stage primaryStage) throws Exception {

        VBox box = new VBox();
        box.setPadding(new Insets(50));

        //设置超链接
        Hyperlink hyperlink = new Hyperlink();

        //设置超链接文本
        hyperlink.setText("www.baidu.com");

        //超链接对应组件
        hyperlink.setGraphic(new Button("网址"));

        //设置是否已访问
        hyperlink.setVisited(false);

        //设置点击事件
        hyperlink.setOnAction(event -> {
            //打开浏览器
            HostServices hostServices = HyperlinkSettingMain.this.getHostServices();
            hostServices.showDocument(hyperlink.getText());
        });

        box.getChildren().add(hyperlink);
        primaryStage.setScene(new Scene(box));
        primaryStage.setWidth(600);
        primaryStage.setHeight(500);
        primaryStage.show();
    }
}
